package com.team5101.lha.team5101.web.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.team5101.dto.ProductDTO;
import com.team5101.entity.TProduct;
import com.team5101.product.api.IProductService;
import com.team5101.vo.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/api/product")
public class ProductController {

    @Reference
    private IProductService iProductService;


    @RequestMapping("/allproducts")
    @ResponseBody
    public ResultBean getAll(){
        List<TProduct> data = iProductService.getAllList();
        ResultBean resultBean = new ResultBean();
        resultBean.success(data);
        return  resultBean.success(data);
    }


    @RequestMapping("/productbyinfo")
    @ResponseBody
    public ResultBean getByItem(@RequestBody ProductDTO productDTO){
        // if(productDTO.getpId()!=null&&productDTO.getpId()!="")
        List<TProduct> data = iProductService.getListByitem(productDTO);
        return new ResultBean().success(data);
    }


    @RequestMapping("/ndproductlist")
    @ResponseBody
    public ResultBean getSecondItem(@RequestBody ProductDTO productDTO){

        List<TProduct> data=iProductService.getListBySecond(productDTO);

        return new ResultBean().success(data);
    }

    @RequestMapping("/stproductlist")
    @ResponseBody
    public ResultBean getFirstItem(@RequestBody ProductDTO productDTO){
        List<TProduct> data=iProductService.getListByFirst(productDTO);
        return new ResultBean().success(data);
    }

}
